<?php

namespace app\common\model;

use think\Model;


class Evaluation extends Model
{

    

    

    // 表名
    protected $name = 'evaluation';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'evaluation_text',
        'images_array'

    ];
    
    public function getImagesArrayAttr($value, $data)
    {
        $arr = explode(',', $data['images']);
        foreach ($arr as &$v) {
            $v = cdnurl($v, true);
        }
        return $arr;
    }

    
    public function getEvaluationList()
    {
        return ['0' => __('Evaluation 0'), '1' => __('Evaluation 1'), '2' => __('Evaluation 2')];
    }


    public function getEvaluationTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['evaluation']) ? $data['evaluation'] : '');
        $list = $this->getEvaluationList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function escort()
    {
        return $this->belongsTo('app\common\model\User', 'escort_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function user()
    {
        return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function order()
    {
        return $this->belongsTo('app\common\model\service\Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
